from typing import Optional
from app.api.schemas import (
    TextTransPayload,
    TextTransResponse,
    FileTransPayload,
    FileTransResponse,
)
from app.api.services.translators import TranslateClient

from app.config import logger


class TranslationService:
    """
    翻译服务类。
    """

    async def translate_text(self, payload: TextTransPayload) -> TextTransResponse:
        logger.info(f"Translate text: {payload.text}")

        return TextTransResponse(
            errno=0,
            msg="ok",
            result=TranslateClient.translate_text(
                payload.text, payload.from_lang, payload.to_lang
            ),
        )

    async def translate_file(self, payload: FileTransPayload) -> FileTransResponse:
        # 假设翻译后的文件信息
        translated_files = [
            FileTransResponse._TransResultItem(
                id="123456",
                name="translated_file.docx",
                status="completed",
                url="https://example.com/translated_file.docx",
            )
        ]
        return FileTransResponse(
            errno=0,
            msg="ok",
            type="file",
            task_id="123456",
            procss=100,
            data=translated_files,
        )
